var express = require('express');
var request = require('request');
var app = express();

//设置跨域访问
app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By", ' 3.2.1');
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});

//查询城市的天气
app.get('/getCityWeather', function(req, res) {
    res.status(200),
        res.json(123)
        // var request = require('request');
        // request('请求url', function (error, response, body) {
        //   if (!error && response.statusCode == 200) {
        //     console.log(body) // 请求成功的处理逻辑，注意body是json字符串
        //   }
        // });
});

//配置服务端口
var server = app.listen(8568, function() {

    var host = server.address().address;

    var port = server.address().port;

    console.log('服务启动！', host, port);
})